﻿Imports RelatedObjects.Storage
Imports System
Imports System.IO
Imports System.Text
Imports RelatedObjects.Storage.IBaseStorageWrapper.FileObjects

Namespace Parsing
    Public Class CHMParser
        ' Methods
        Public Function Parse(ByVal chmFilePath As String) As String
            Dim wrapper As New ITStorageWrapper(chmFilePath)
            Dim builder As New StringBuilder
            Dim obj2 As FileObject
            For Each obj2 In wrapper.foCollection
                If (obj2.CanRead AndAlso obj2.FileName.EndsWith(".htm")) Then
                    Dim num As Integer
                    Dim stream As Stream = New MemoryStream
                    Dim buffer As Byte() = New Byte(Convert.ToInt32(obj2.Length) - 1) {}
                    obj2.Seek(0, SeekOrigin.Begin)
                    num = obj2.Read(buffer, 0, &H400)
                    Do While (num > 0)
                        stream.Write(buffer, 0, num)
                        num = obj2.Read(buffer, 0, &H400)
                    Loop
                    stream.Seek(0, SeekOrigin.Begin)
                    Dim reader As New StreamReader(stream, Encoding.Default)
                    builder.Append(reader.ReadToEnd.ToString)
                End If
            Next
            Return builder.ToString
        End Function

    End Class
End Namespace

